import axios from 'axios'
import request from '@neu/biz-core/utils/request'
import { getToken } from '@neu/biz-core/utils/auth'

export const page = () => {
  return request({
    url: '/cmdb/relations/page',
    method: 'get'
  })
}

export const detail = (id) => {
  return request({
    url: '/cmdb/relations/' + id,
    method: 'get'
  })
}

export const update = (id, data) => {
  return request({
    url: '/cmdb/relations/' + id,
    data: data,
    method: 'put'
  })
}

export const remove = (id) => {
  return request({
    url: '/cmdb/relations/' + id,
    method: 'delete'
  })
}

export const simpleList = () => {
  return request({
    url: '/cmdb/relations/list/simple',
    method: 'get'
  })
}

export const getTpl = (relationId) => {
  const url = '/cmdb/relations/' + relationId + '/tpl'
  return new Promise((resolve, reject) => {
    axios.get(url, { responseType: 'blob', headers: { 'Authentication': getToken() }})
      .then(response => {
        resolve(response)
      })
      .catch(error => {
        reject(error)
      })
  })
}
